import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

/* 解决重复点击相同导航报错 */
//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [{
  path: '/',
  name: 'Home',
  component: () => import('../views/Home.vue')
},
{
  path: '/article/:id',
  name: 'Article',
  component: () => import('../views/Article.vue')
},
{
  path: '/tag/:id',
  name: 'Tag',
  component: () => import('../views/Tag.vue'),
},
{
  path: '/timeline',
  name: 'Timeline',
  component: () => import('../views/Timeline.vue')
},
{
  path: '/message',
  name: 'Message',
  component: () => import('../views/Message.vue')
},
{
  path: '/about',
  name: 'About',
  component: () => import('../views/About.vue')
},
{
  path: '/user',
  name: 'User',
  component: () => import('../views/User.vue')
},
{
  path: '*',
  name: '404',
  component: () => import('../views/common/404.vue')
}
]

const router = new VueRouter({
  routes
})

export default router